<template>
  <div class="main-content cooDeptAudit">
    <div class="screen-frame clearfix">
      <div class="col-md-7">
        <div class="form-horizontal">
          <div class="form-group">
            <label class="col-md-3 col-sm-2 control-label">条件查询：</label>
            <div class="col-md-8 col-sm-10">
              <input type="text"
                     class="form-control"
                     placeholder="管理员姓名、电话"
                     v-model="params.condition">
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-5">
        <div class="form-horizontal">
          <div class="form-group">
            <label class="col-md-4 col-sm-2 control-label">审核状态：</label>
            <div class="col-md-5 col-sm-10">
              <select class="form-control"
                      v-model="params.checkStatus">
                <option value="">全部</option>
                <option value="0">待审核</option>
                <option value="2">审核通过</option>
                <option value="1">审核失败</option>
              </select>
              <button type="submit"
                      class="btn screen-submit"
                      v-on:click="getAgentOrgAuditPage(1)">查询</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="inviteCode"
         v-if="inviteCode">
      机构自主注册邀请码：{{inviteCode}}
    </div>
    <table class="table table-striped table-bordered">
      <thead>
        <tr>
          <th width="1%">序号</th>
          <th width="3%">公司名称</th>
          <th width="2%">省份</th>
          <th width="2%">城市</th>
          <th width="4%">详细地址</th>
          <th width="2%">管理员</th>
          <th width="2%">联系电话</th>
          <th width="5%">提交时间</th>
          <th width="3%">审核状态</th>
          <th width="1%">操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(row, index) in agentOrgAuditList">
          <td>{{index+1}}</td>
          <td>{{row.companyName}}</td>
          <td>{{row.provinceName}}</td>
          <td>{{row.cityName}}</td>
          <td>{{row.adress}}</td>
          <td>{{row.adminName}}</td>
          <td>{{row.adminPhone}}</td>
          <td>{{row.createTime}}</td>
          <td>{{row.status==1?"审核失败":row.status==2?"审核通过":"待审核"}}</td>
          <td>
            <a v-on:click="openCooDeptAuditModal(row,false)"
               class="btnA edit">查看</a>
            <a v-if="row.status == 0"
               v-on:click="openCooDeptAuditModal(row,true)"
               class="btnA edit"
               v-res="{code:'menu_0003_0004_0001'}">审核</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div id="laypage_coo_dept_audit"></div>
    <cooDeptAutidModal v-bind:cooDeptAudit="cooDeptAuditInfo"
                       :editFlag="editFlag"
                       v-on:cooDeptAuditListener='cooDeptAuditReturn'></cooDeptAutidModal>
  </div>
</template>
<script>
import cooDeptAutidModal from "./cooDeptAuditModal.vue";
export default {
  data() {
    return {
      params: {
        pageNo: 1,
        pageSize: 10,
        condition: "",
        checkStatus: ""
      },
      agentOrgAuditList: [],
      cooDeptAuditInfo: {},
      inviteCode: "",
      editFlag: false
    };
  },
  components: {
    cooDeptAutidModal
  },
  mounted: function () {
    //初始化加载
    this.getAgentOrgAuditPage(1);
  },
  methods: {
    getAgentOrgAuditPage: function (type) {
      var _self = this;
      //判断点查询按钮时，将当前页和条数设置为默认
      if (type == "1") {
        _self.params.pageNo = 1;
        _self.params.pageSize = 10;
      }
      var body = {};
      body.params = _self.params;
      var url = this.utilHelper.apiUrl + "/api/getAgentCompanyRegesitList";
      _self.$http.post(url, body).then((response) => {
        if (response.body.result == "1" && response.body.resData) {
          const orgAuditPage = response.body.resData.agentCompanyRegesitPage;
          this.inviteCode = response.body.resData.companyId || "";
          _self.agentOrgAuditList = orgAuditPage.rows;
          var totalPages = orgAuditPage.totalPages;
          var total = orgAuditPage.total;
          var current = _self.params.pageNo;
          if (totalPages >= 0) {
            layui.laypage.render({
              elem: $("#laypage_coo_dept_audit"), //容器。值支持id名、原生dom对象，jquery对象,
              limit: _self.params.pageSize,
              curr: current,
              count: total,
              theme: "#f87242;", //皮肤
              first: "首页", //若不显示，设置false即可
              last: "尾页", //若不显示，设置false即可
              prev: "上一页", //若不显示，设置false即可
              next: "下一页", //若不显示，设置false即可
              layout: ["prev", "page", "next", "skip", "count"],
              jump: function (obj, first) {
                if (!first) {
                  _self.params.pageNo = obj.curr;
                  _self.getAgentOrgAuditPage(0);
                }
              }
            });
          }
        } else {
          console.log(response);
        }
      });
    },
    openCooDeptAuditModal: function (obj, edit) {
      this.cooDeptAuditInfo = obj;
      this.editFlag = edit;
      $("#cooDeptAuditModal").modal("show");
    },
    cooDeptAuditReturn: function () {
      this.getAgentOrgAuditPage();
    }
  }
};
</script>
<style lang="less" scoped>
.inviteCode {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
}
.cooDeptAudit {
  padding-left: 20px;
}
</style>